﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MuYue.Config
{
    public class AppConfigThreadManger
    {
        #region 存储事件
        /// <summary>
        /// 配置持久化提供程序
        /// </summary>
        private static AppConfigReadWriteProvider dal;

        /// <summary>
        /// 启动配置提供
        /// 将持久化存储与配置读写关联
        /// </summary>
        public static void Start()
        {
            if (dal != null)
                return;
            dal = new AppConfigReadWriteProvider();
            AppConfigManager.SqliteReadEvent += dal.AppConfigManager_SqliteReadEvent;
            AppConfigManager.InsertConfigItemEvent += dal.AppConfigManager_InsertConfigItemEvent;
            AppConfigManager.UpdateConfigItemEvent += dal.AppConfigManager_UpdateConfigItemEvent;
        }

        /// <summary>
        /// 关闭配置提供
        /// 取消持久化关联
        /// </summary>
        public static void Stop()
        {
            if (dal == null)
                return;
            AppConfigManager.SqliteReadEvent -= dal.AppConfigManager_SqliteReadEvent;
            AppConfigManager.InsertConfigItemEvent -= dal.AppConfigManager_InsertConfigItemEvent;
            AppConfigManager.UpdateConfigItemEvent -= dal.AppConfigManager_UpdateConfigItemEvent;
            dal.Dispose();
            dal = null;
        }

        #endregion
    }
}
